<?php
GLOBAL $AppUI, $obj, $project_id, $deny, $canRead, $canEdit, $dPconfig;

if (!defined('DP_BASE_DIR')) {
	echo 'You should not access this file directly.';
	exit();
}

$root = defined('DP_PROJECT_DIR') ? DP_PROJECT_DIR : DP_BASE_DIR.'/files/projects';
$root .= '/' . $obj->project_id;

$q = new DBQuery();
$q->addTable('files', 'f');
$q->addQuery('f.*, t.task_name');
$q->addJoin('tasks', 't', 'f.file_task = t.task_id');
$q->addWhere('f.file_project = '.$obj->project_id);
$q->addOrder('task_start_date');
$q->addOrder('file_name');
$data = $q->loadHashList('file_real_filename');
$total = count($data);

$size = 0;
foreach ($data as $d)
	$size += $d['file_size'];
?>
<table border="0" cellpadding="7" cellspacing="0" class="infopanel" width="100%">
<tr>
	<td class="status">Total:</td><td><?=$total?>&nbsp;file<?=$total > 1 ? 's' : ''?></td>
	<td class="status">Utilized:</td><td><?=$size?>&nbsp;byte<?=$size > 1 ? 's' : ''?></td>
	<td width="100%">&nbsp;</td>
</tr>
</table>
<table id="idFileList" border="0" cellpadding="0" cellspacing="0" class="list" width="100%">
<tr>
	<th width="14px">&nbsp;</th>
	<th nowrap="nowrap">File name</th>
	<th width="30px">Ver.</th>
	<th width="45px">Owner</th>
	<th width="45px">Size</th>
	<th width="100px">Date</th>
	<th width="100%">Description</th>
	<th width="14px" class="last">&nbsp;</th>
</tr>
<?
$task_name = '';
if ($total == 0) {
	showEmptyRow(8, 'second');
}
else
foreach ($data as $f => $d) {
	$task_folder = $root . '/' . $d['file_task'];
	if (file_exists($task_folder . '/' . $f)) {
		if ($task_name != $d['task_name']) {
			$task_name = $d['task_name'];
			echo '<tr onclick="go(\'index.php?m=tasks&a=view&task_id='.$d['file_task'].'\')">'.
					'<td><img src="images/folder.gif"/></td><td colspan="7">'.$task_name.'</td>'.
				'</tr>';
		}
?>
<tr id="<?=$f?>" class="second">
	<td id="<?=$d['file_task']?>" align="center">
		<img src="images/log.gif"/>
	</td>
	<td nowrap="nowrap" onclick="doViewFile(this)"><?=$d['file_name']?></td>
	<td><?=sprintf('%.2f', $d['file_version'])?></td>
	<td nowrap="nowrap"><?=dPgetUsernameFromID($d['file_owner'])?></td>
	<td onclick="doViewFile(this)"><?=$d['file_size']?></td>
	<td nowrap="nowrap" onclick="doViewFile(this)"><?=substr($d['file_date'], 0, strrpos($d['file_date'], ':'))?></td>
	<td onclick="doViewFile(this)"><?=$d['file_description']?></td>
	<td align="center">
		<img src="images/nodel_log.gif"/>
	</td>
</tr>
<?
	}
}
?>
</table>
<script>
function doViewFile(cell)
{
	var fn = cell.parentNode.id;
	var tid = cell.parentNode.cells[0].id;
	go('index.php?m=tasks&a=file&suppressHeaders=1&cmd=get&file='+fn+
		'&project=<?=$obj->project_id?>&task='+tid, 'sdp_fileviewer');
}

Table('idFileList').setNormalHover(1);
</script>
